package com.liuceng.peatio.service

import com.liuceng.peatio.model.FrontAdGroup
import spock.lang.Specification

/**
 * Created by liyuhang on 2016-13-11.
 */
class FrontAdGroupServiceSpec extends Specification {

    def "test .groupByMemberId"() {
        given:
        List<FrontAdGroup> adgroups = [new FrontAdGroup(id: 1, memberId: 1), new FrontAdGroup(id: 2, memberId: 2), new FrontAdGroup(id: 3, memberId: 1)]

        when:
        Map<Integer, List<FrontAdGroup>> grouped = new FrontAdGroupService().groupByMemberId(adgroups)

        then:
        grouped == [
                1: [new FrontAdGroup(id: 1, memberId: 1), new FrontAdGroup(id: 3, memberId: 1)],
                2: [new FrontAdGroup(id: 2, memberId: 2)]
        ]
    }

    def "test .groupByCampaignType"() {
        given:
        List<FrontAdGroup> adgroups = [new FrontAdGroup(id: 1, frontCampaignType: 1), new FrontAdGroup(id: 2, frontCampaignType: 2), new FrontAdGroup(id: 3, frontCampaignType: 1)]

        when:
        Map<Integer, List<FrontAdGroup>> grouped = new FrontAdGroupService().groupByCampaignType(adgroups)

        then:
        grouped == [
                1: [new FrontAdGroup(id: 1, frontCampaignType: 1), new FrontAdGroup(id: 3, frontCampaignType: 1)],
                2: [new FrontAdGroup(id: 2, frontCampaignType: 2)]
        ]
    }

}